filelist=$(readlink -f $1)
mac=$2

echo filelist $filelist
echo mac $mac

id=C2

###############################################

dir0=job$id

mkdir -p $dir0

echo inputing...

nf=$(wc $filelist | awk '{print $1}')
echo nf $nf
#test
#nf=3

ls -lhtB $mac*

root -b -l <<EOF
.L $mac.C+
.q
EOF

ls -lhtB $mac*

####################################################

cp $mac*.so $dir0
cp $mac.C $dir0

cd $dir0

echo $filelist $mac > inlog

ln -s /data/t2k/xlu/software/t2k/nd280/nd280AnalysisTools/v0r7p1/AnalysisTools

ii=1

while [ $ii -le $nf ]
do
    ff=$(head -n $ii $filelist | tail -n 1)
    jobfile=$id\n$ii.sh

    eof=EOF
    cat > $jobfile <<EOF
source $(readlink -f ~/t2ksoft.sh)

cd $(pwd)

date

root -l -b << $eof
.L $mac.C+
$mac t
t.DoAnalysis("$ff", 50000000, "$ii")
.q
$eof

date

EOF

    chmod +x $jobfile


   qsub -l cput=00:10:00 -N $jobfile  ./$jobfile 

   nq=$(qstat | grep $(whoami) | grep Q |wc | awk '{print $1}' )
   while [ $nq -gt 10 ]
   do
       sleep 10
       nq=$(qstat | grep $(whoami) | grep Q |wc | awk '{print $1}' )
   done

    ii=$( expr $ii + 1 )

done



echo done $ii

